from tables import tablesDatabase
from multiprocessing import Process, Pipe
import py_compile
import imp

class RunPython:

    def __init__(self):
        # instialise the process creation
        return

    def parse(self, code, table, username, database, operation):
        columns = tablesDatabase(database).getTableColumns(table)
        columsString = ""
        for column in columns:
            columnsString = columnsString + column + ", "
        "def {0}({1}):".format(operation, columnsString[:-2])
        statements = code.split("/n")
        for statement in statements:
            columnsString = columnsString + "/t{0}/n".format(statment)
        filename = "../operations/{0}/{1}.py".format(username, operation)
        fp = open(filename, "w")
        fp.write(columsString)
        fp.close()
        py_compile.compile(filename)
        py_mod = imp.load_compiled(operation, filename + "c")
        dataTable = tablesDatabase(database).getTable(table)

    def runCode(table, filename):
        return
